{
 "cells": [
  {
   "cell_type": "code",
   "id": "fd7a6aaf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:34.943122Z",
     "start_time": "2025-05-25T03:01:34.883864Z"
    }
   },
   "source": [
    "import pypandoc\n",
    "import os\n",
    "import pathlib\n",
    "import fuzzywuzzy\n",
    "from fuzzywuzzy import fuzz\n",
    "import shutil\n",
    "sources = set(os.listdir(\"md\"))\n",
    "# sources"
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "id": "a6deda9e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:34.963762Z",
     "start_time": "2025-05-25T03:01:34.959766Z"
    }
   },
   "source": [
    "src_path = pathlib.Path(\"..\")/\"..\"/\"..\"/\"..\"/\"..\"/\"..\"\\\n",
    "    /\"src\"/\"main\"/\"java\"/\\\n",
    "    \"cn\"/\"edu\"/\"usst\"/\"cs\"/\"campusAid\"\n",
    "print(src_path.exists())\n",
    "package_names=[i for i in os.listdir(src_path) if not '.java' in i]\n",
    "print(package_names)\n",
    "print(src_path.resolve().absolute())\n",
    "# print(pathlib.Path(\".\").absolute())"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "['config', 'controller', 'dto', 'handler', 'interceptor', 'mapper', 'model', 'service', 'util']\n",
      "C:\\Users\\jerry\\IdeaProjects\\campusAid\\src\\main\\java\\cn\\edu\\usst\\cs\\campusAid\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "id": "a47bfcf0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:35.109288Z",
     "start_time": "2025-05-25T03:01:35.105810Z"
    }
   },
   "source": [
    "packages = {}"
   ],
   "outputs": [],
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "id": "6e695c02",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:35.122529Z",
     "start_time": "2025-05-25T03:01:35.119318Z"
    }
   },
   "source": [
    "def get_package_name(class_name):\n",
    "    for package_name in package_names:\n",
    "        package = src_path / package_name\n",
    "        max_rate = 0\n",
    "        for file in package.rglob(\"*.java\"):\n",
    "            rate = fuzz.ratio(class_name, file.name.replace(\".java\", \"\")) \n",
    "            if rate > max_rate:\n",
    "                max_rate = rate\n",
    "            if max_rate > 80:\n",
    "                return package_name\n",
    "        print(f\"Class name {class_name} does not match with {package.name}, rate: {max_rate}\")\n",
    "    raise FileNotFoundError(f\"Class {class_name} not found in any package.\")"
   ],
   "outputs": [],
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "id": "4ff32712",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:35.239833Z",
     "start_time": "2025-05-25T03:01:35.234698Z"
    }
   },
   "source": [
    "candidates = [ filename.split(\".\")[0] for filename in sources if filename.endswith(\".md\") ]\n",
    "len(candidates)"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "108"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "id": "41c5aa4d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:35.480268Z",
     "start_time": "2025-05-25T03:01:35.277509Z"
    }
   },
   "source": [
    "for class_name in candidates:\n",
    "    if class_name == \"CampusAidApplication\":\n",
    "        continue\n",
    "    if \"impl\" in class_name.lower():\n",
    "        continue\n",
    "    try:\n",
    "        package = get_package_name(class_name)\n",
    "    except:\n",
    "        print(f\"Class {class_name} not found in any package.\")\n",
    "        continue\n",
    "    if package in packages.keys():\n",
    "        packages[package].add(class_name)\n",
    "    else:\n",
    "        packages[package] = {class_name}\n",
    "# packages"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Class name BanInterceptor does not match with config, rate: 31\n",
      "Class name BanInterceptor does not match with controller, rate: 47\n",
      "Class name BanInterceptor does not match with dto, rate: 40\n",
      "Class name BanInterceptor does not match with handler, rate: 39\n",
      "Class name ForumInterceptorTemplated does not match with config, rate: 46\n",
      "Class name ForumInterceptorTemplated does not match with controller, rate: 55\n",
      "Class name ForumInterceptorTemplated does not match with dto, rate: 44\n",
      "Class name ForumInterceptorTemplated does not match with handler, rate: 34\n",
      "Class name ForumInterceptorTemplated does not match with interceptor, rate: 64\n",
      "Class name ForumInterceptorTemplated does not match with mapper, rate: 38\n",
      "Class name ForumInterceptorTemplated does not match with model, rate: 35\n",
      "Class name ForumInterceptorTemplated does not match with service, rate: 58\n",
      "Class name ForumInterceptorTemplated does not match with util, rate: 33\n",
      "Class ForumInterceptorTemplated not found in any package.\n",
      "Class name OrderMapper does not match with config, rate: 34\n",
      "Class name OrderMapper does not match with controller, rate: 37\n",
      "Class name OrderMapper does not match with dto, rate: 62\n",
      "Class name OrderMapper does not match with handler, rate: 24\n",
      "Class name OrderMapper does not match with interceptor, rate: 32\n",
      "Class name Ban does not match with config, rate: 17\n",
      "Class name Ban does not match with controller, rate: 21\n",
      "Class name Ban does not match with dto, rate: 24\n",
      "Class name Ban does not match with handler, rate: 16\n",
      "Class name Ban does not match with interceptor, rate: 32\n",
      "Class name Ban does not match with mapper, rate: 50\n",
      "Class name ErrandViewsMapper does not match with config, rate: 29\n",
      "Class name ErrandViewsMapper does not match with controller, rate: 48\n",
      "Class name ErrandViewsMapper does not match with dto, rate: 51\n",
      "Class name ErrandViewsMapper does not match with handler, rate: 31\n",
      "Class name ErrandViewsMapper does not match with interceptor, rate: 42\n",
      "Class name StockController does not match with config, rate: 42\n",
      "Class name UserMapper does not match with config, rate: 36\n",
      "Class name UserMapper does not match with controller, rate: 50\n",
      "Class name UserMapper does not match with dto, rate: 40\n",
      "Class name UserMapper does not match with handler, rate: 25\n",
      "Class name UserMapper does not match with interceptor, rate: 38\n",
      "Class name CampusAidException does not match with config, rate: 34\n",
      "Class name CampusAidException does not match with controller, rate: 38\n",
      "Class name CampusAidException does not match with dto, rate: 41\n",
      "Class name CampusAidException does not match with handler, rate: 50\n",
      "Class name CampusAidException does not match with interceptor, rate: 47\n",
      "Class name CampusAidException does not match with mapper, rate: 55\n",
      "Class name CampusAidException does not match with model, rate: 42\n",
      "Class name ErrandService does not match with config, rate: 39\n",
      "Class name ErrandService does not match with controller, rate: 55\n",
      "Class name ErrandService does not match with dto, rate: 71\n",
      "Class name ErrandService does not match with handler, rate: 34\n",
      "Class name ErrandService does not match with interceptor, rate: 51\n",
      "Class name ErrandService does not match with mapper, rate: 64\n",
      "Class name ErrandService does not match with model, rate: 63\n",
      "Class name ComplaintService does not match with config, rate: 40\n",
      "Class name ComplaintService does not match with controller, rate: 63\n",
      "Class name ComplaintService does not match with dto, rate: 69\n",
      "Class name ComplaintService does not match with handler, rate: 32\n",
      "Class name ComplaintService does not match with interceptor, rate: 53\n",
      "Class name ComplaintService does not match with mapper, rate: 71\n",
      "Class name ComplaintService does not match with model, rate: 72\n",
      "Class name BanApiInterceptor does not match with config, rate: 32\n",
      "Class name BanApiInterceptor does not match with controller, rate: 42\n",
      "Class name BanApiInterceptor does not match with dto, rate: 43\n",
      "Class name BanApiInterceptor does not match with handler, rate: 36\n",
      "Class name ShopOrder does not match with config, rate: 37\n",
      "Class name ShopOrder does not match with controller, rate: 61\n",
      "Class name ShopOrder does not match with dto, rate: 71\n",
      "Class name ShopOrder does not match with handler, rate: 32\n",
      "Class name ShopOrder does not match with interceptor, rate: 35\n",
      "Class name ShopOrder does not match with mapper, rate: 63\n",
      "Class name ErrandOrderRequest does not match with config, rate: 33\n",
      "Class name ErrandOrderRequest does not match with controller, rate: 53\n",
      "Class name ChargeMapper does not match with config, rate: 31\n",
      "Class name ChargeMapper does not match with controller, rate: 32\n",
      "Class name ChargeMapper does not match with dto, rate: 35\n",
      "Class name ChargeMapper does not match with handler, rate: 29\n",
      "Class name ChargeMapper does not match with interceptor, rate: 37\n",
      "Class name LoginService does not match with config, rate: 33\n",
      "Class name LoginService does not match with controller, rate: 52\n",
      "Class name LoginService does not match with dto, rate: 58\n",
      "Class name LoginService does not match with handler, rate: 29\n",
      "Class name LoginService does not match with interceptor, rate: 46\n",
      "Class name LoginService does not match with mapper, rate: 38\n",
      "Class name LoginService does not match with model, rate: 30\n",
      "Class name ShopController does not match with config, rate: 38\n",
      "Class name Order does not match with config, rate: 26\n",
      "Class name Order does not match with controller, rate: 38\n",
      "Class name PostSortOrder does not match with config, rate: 39\n",
      "Class name PostSortOrder does not match with controller, rate: 45\n",
      "Class name LikeBlogMapper does not match with config, rate: 36\n",
      "Class name LikeBlogMapper does not match with controller, rate: 34\n",
      "Class name LikeBlogMapper does not match with dto, rate: 32\n",
      "Class name LikeBlogMapper does not match with handler, rate: 33\n",
      "Class name LikeBlogMapper does not match with interceptor, rate: 32\n",
      "Class name ReplyView does not match with config, rate: 35\n",
      "Class name ReplyView does not match with controller, rate: 30\n",
      "Class name RegisterRequest does not match with config, rate: 42\n",
      "Class name RegisterRequest does not match with controller, rate: 55\n",
      "Class name Visibility does not match with config, rate: 25\n",
      "Class name Visibility does not match with controller, rate: 29\n",
      "Class name UserController does not match with config, rate: 44\n",
      "Class name BaseAuthService does not match with config, rate: 42\n",
      "Class name BaseAuthService does not match with controller, rate: 34\n",
      "Class name BaseAuthService does not match with dto, rate: 39\n",
      "Class name BaseAuthService does not match with handler, rate: 27\n",
      "Class name BaseAuthService does not match with interceptor, rate: 53\n",
      "Class name BaseAuthService does not match with mapper, rate: 38\n",
      "Class name BaseAuthService does not match with model, rate: 32\n",
      "Class name OrderDTO does not match with config, rate: 23\n",
      "Class name OrderDTO does not match with controller, rate: 33\n",
      "Class name ForumPostService does not match with config, rate: 41\n",
      "Class name ForumPostService does not match with controller, rate: 58\n",
      "Class name VerifyRequest does not match with config, rate: 45\n",
      "Class name VerifyRequest does not match with controller, rate: 33\n",
      "Class name SessionKeys does not match with config, rate: 41\n",
      "Class name ExceptionService does not match with config, rate: 41\n",
      "Class name ExceptionService does not match with controller, rate: 37\n",
      "Class name ExceptionService does not match with dto, rate: 41\n",
      "Class name ExceptionService does not match with handler, rate: 58\n",
      "Class name ExceptionService does not match with interceptor, rate: 47\n",
      "Class name ExceptionService does not match with mapper, rate: 71\n",
      "Class name ExceptionService does not match with model, rate: 32\n",
      "Class name ComplaintController does not match with config, rate: 40\n",
      "Class name ProductTransaction does not match with config, rate: 33\n",
      "Class name ProductTransaction does not match with controller, rate: 36\n",
      "Class name ComplaintDTOMapper does not match with config, rate: 38\n",
      "Class name ComplaintDTOMapper does not match with controller, rate: 59\n",
      "Class name ComplaintDTOMapper does not match with dto, rate: 59\n",
      "Class name ComplaintDTOMapper does not match with handler, rate: 35\n",
      "Class name ComplaintDTOMapper does not match with interceptor, rate: 39\n",
      "Class name GoodTransaction does not match with config, rate: 31\n",
      "Class name GoodTransaction does not match with controller, rate: 35\n",
      "Class name GoodTransaction does not match with dto, rate: 79\n",
      "Class name GoodTransaction does not match with handler, rate: 43\n",
      "Class name GoodTransaction does not match with interceptor, rate: 34\n",
      "Class name GoodTransaction does not match with mapper, rate: 77\n",
      "Class name log does not match with config, rate: 33\n",
      "Class name log does not match with controller, rate: 22\n",
      "Class name log does not match with dto, rate: 27\n",
      "Class name log does not match with handler, rate: 16\n",
      "Class name log does not match with interceptor, rate: 15\n",
      "Class name log does not match with mapper, rate: 46\n",
      "Class name ReplyTreeNode does not match with config, rate: 37\n",
      "Class name ReplyTreeNode does not match with controller, rate: 34\n",
      "Class name ReplyTreeNode does not match with dto, rate: 55\n",
      "Class name ReplyTreeNode does not match with handler, rate: 29\n",
      "Class name ReplyTreeNode does not match with interceptor, rate: 37\n",
      "Class name ReplyTreeNode does not match with mapper, rate: 50\n",
      "Class name TemplatedForumInterceptor does not match with config, rate: 41\n",
      "Class name TemplatedForumInterceptor does not match with controller, rate: 50\n",
      "Class name TemplatedForumInterceptor does not match with dto, rate: 44\n",
      "Class name TemplatedForumInterceptor does not match with handler, rate: 34\n",
      "Class name ApiResponse does not match with config, rate: 40\n",
      "Class name ApiResponse does not match with controller, rate: 45\n",
      "Class name BanMapper does not match with config, rate: 26\n",
      "Class name BanMapper does not match with controller, rate: 32\n",
      "Class name BanMapper does not match with dto, rate: 31\n",
      "Class name BanMapper does not match with handler, rate: 32\n",
      "Class name BanMapper does not match with interceptor, rate: 46\n",
      "Class name LocalUploadFileSystemService does not match with config, rate: 33\n",
      "Class name LocalUploadFileSystemService does not match with controller, rate: 34\n",
      "Class name LocalUploadFileSystemService does not match with dto, rate: 36\n",
      "Class name LocalUploadFileSystemService does not match with handler, rate: 40\n",
      "Class name LocalUploadFileSystemService does not match with interceptor, rate: 38\n",
      "Class name LocalUploadFileSystemService does not match with mapper, rate: 37\n",
      "Class name LocalUploadFileSystemService does not match with model, rate: 32\n",
      "Class name Charge does not match with config, rate: 27\n",
      "Class name Charge does not match with controller, rate: 32\n",
      "Class name Charge does not match with dto, rate: 36\n",
      "Class name Charge does not match with handler, rate: 14\n",
      "Class name Charge does not match with interceptor, rate: 29\n",
      "Class name Charge does not match with mapper, rate: 67\n",
      "Class name StockService does not match with config, rate: 47\n",
      "Class name StockService does not match with controller, rate: 52\n",
      "Class name StockService does not match with dto, rate: 36\n",
      "Class name StockService does not match with handler, rate: 29\n",
      "Class name StockService does not match with interceptor, rate: 38\n",
      "Class name StockService does not match with mapper, rate: 36\n",
      "Class name StockService does not match with model, rate: 38\n",
      "Class name Reply does not match with config, rate: 32\n",
      "Class name Reply does not match with controller, rate: 26\n",
      "Class name Reply does not match with dto, rate: 71\n",
      "Class name Reply does not match with handler, rate: 22\n",
      "Class name Reply does not match with interceptor, rate: 21\n",
      "Class name Reply does not match with mapper, rate: 62\n",
      "Class name Complaint does not match with config, rate: 43\n",
      "Class name Complaint does not match with controller, rate: 64\n",
      "Class name Complaint does not match with dto, rate: 78\n",
      "Class name Complaint does not match with handler, rate: 26\n",
      "Class name Complaint does not match with interceptor, rate: 38\n",
      "Class name Complaint does not match with mapper, rate: 75\n",
      "Class name ForumController does not match with config, rate: 36\n",
      "Class name BasicInterceptor does not match with config, rate: 29\n",
      "Class name BasicInterceptor does not match with controller, rate: 41\n",
      "Class name BasicInterceptor does not match with dto, rate: 44\n",
      "Class name BasicInterceptor does not match with handler, rate: 37\n",
      "Class name RegisterController does not match with config, rate: 39\n",
      "Class name ReplyTreeConverter does not match with config, rate: 44\n",
      "Class name ReplyTreeConverter does not match with controller, rate: 50\n",
      "Class name ReplyTreeConverter does not match with dto, rate: 45\n",
      "Class name ReplyTreeConverter does not match with handler, rate: 30\n",
      "Class name ReplyTreeConverter does not match with interceptor, rate: 47\n",
      "Class name ReplyTreeConverter does not match with mapper, rate: 51\n",
      "Class name ReplyTreeConverter does not match with model, rate: 71\n",
      "Class name ReplyTreeConverter does not match with service, rate: 41\n",
      "Class name BanBlock does not match with config, rate: 21\n",
      "Class name BanBlock does not match with controller, rate: 26\n",
      "Class name BanBlock does not match with dto, rate: 64\n",
      "Class name BanBlock does not match with handler, rate: 20\n",
      "Class name BanBlock does not match with interceptor, rate: 33\n",
      "Class name BanBlock does not match with mapper, rate: 35\n",
      "Class name ComplaintRequest does not match with config, rate: 40\n",
      "Class name ComplaintRequest does not match with controller, rate: 57\n",
      "Class name LoginController does not match with config, rate: 38\n",
      "Class name TransactionMapper does not match with config, rate: 34\n",
      "Class name TransactionMapper does not match with controller, rate: 42\n",
      "Class name TransactionMapper does not match with dto, rate: 63\n",
      "Class name TransactionMapper does not match with handler, rate: 46\n",
      "Class name TransactionMapper does not match with interceptor, rate: 37\n",
      "Class name UploadFileSystemService does not match with config, rate: 32\n",
      "Class name UploadFileSystemService does not match with controller, rate: 33\n",
      "Class name UploadFileSystemService does not match with dto, rate: 36\n",
      "Class name UploadFileSystemService does not match with handler, rate: 36\n",
      "Class name UploadFileSystemService does not match with interceptor, rate: 42\n",
      "Class name UploadFileSystemService does not match with mapper, rate: 40\n",
      "Class name UploadFileSystemService does not match with model, rate: 33\n",
      "Class name ApiInterceptor does not match with config, rate: 36\n",
      "Class name ApiInterceptor does not match with controller, rate: 47\n",
      "Class name ApiInterceptor does not match with dto, rate: 48\n",
      "Class name ApiInterceptor does not match with handler, rate: 33\n",
      "Class name AuthInterceptor does not match with config, rate: 30\n",
      "Class name AuthInterceptor does not match with controller, rate: 41\n",
      "Class name AuthInterceptor does not match with dto, rate: 36\n",
      "Class name AuthInterceptor does not match with handler, rate: 32\n",
      "Class name ProductToGoodTransaction does not match with config, rate: 29\n",
      "Class name ProductToGoodTransaction does not match with controller, rate: 31\n",
      "Class name ViewInterceptor does not match with config, rate: 30\n",
      "Class name ViewInterceptor does not match with controller, rate: 42\n",
      "Class name ViewInterceptor does not match with dto, rate: 40\n",
      "Class name ViewInterceptor does not match with handler, rate: 32\n",
      "Class name ErrorController does not match with config, rate: 36\n",
      "Class name ReportRequest does not match with config, rate: 39\n",
      "Class name ReportRequest does not match with controller, rate: 33\n",
      "Class name ComplaintMapper does not match with config, rate: 41\n",
      "Class name ComplaintMapper does not match with controller, rate: 65\n",
      "Class name ComplaintMapper does not match with dto, rate: 65\n",
      "Class name ComplaintMapper does not match with handler, rate: 38\n",
      "Class name ComplaintMapper does not match with interceptor, rate: 42\n",
      "Class name ShopService does not match with config, rate: 48\n",
      "Class name ShopService does not match with controller, rate: 48\n",
      "Class name ShopService does not match with dto, rate: 42\n",
      "Class name ShopService does not match with handler, rate: 24\n",
      "Class name ShopService does not match with interceptor, rate: 40\n",
      "Class name ShopService does not match with mapper, rate: 57\n",
      "Class name ShopService does not match with model, rate: 60\n",
      "Class name MailService does not match with config, rate: 34\n",
      "Class name MailService does not match with controller, rate: 36\n",
      "Class name MailService does not match with dto, rate: 41\n",
      "Class name MailService does not match with handler, rate: 30\n",
      "Class name MailService does not match with interceptor, rate: 44\n",
      "Class name MailService does not match with mapper, rate: 40\n",
      "Class name MailService does not match with model, rate: 35\n",
      "Class name ErrandController does not match with config, rate: 35\n",
      "Class name ChargeService does not match with config, rate: 32\n",
      "Class name ChargeService does not match with controller, rate: 33\n",
      "Class name ChargeService does not match with dto, rate: 45\n",
      "Class name ChargeService does not match with handler, rate: 23\n",
      "Class name ChargeService does not match with interceptor, rate: 36\n",
      "Class name ChargeService does not match with mapper, rate: 64\n",
      "Class name ChargeService does not match with model, rate: 63\n",
      "Class name ForumPostPreview does not match with config, rate: 41\n",
      "Class name ForumPostPreview does not match with controller, rate: 58\n",
      "Class name ReplyMapperStruct does not match with config, rate: 34\n",
      "Class name ReplyMapperStruct does not match with controller, rate: 34\n",
      "Class name ReplyMapperStruct does not match with dto, rate: 47\n",
      "Class name ReplyMapperStruct does not match with handler, rate: 26\n",
      "Class name ReplyMapperStruct does not match with interceptor, rate: 48\n",
      "Class name LikeBlog does not match with config, rate: 35\n",
      "Class name LikeBlog does not match with controller, rate: 26\n",
      "Class name LikeBlog does not match with dto, rate: 36\n",
      "Class name LikeBlog does not match with handler, rate: 13\n",
      "Class name LikeBlog does not match with interceptor, rate: 27\n",
      "Class name LikeBlog does not match with mapper, rate: 73\n",
      "Class name Blog does not match with config, rate: 31\n",
      "Class name Blog does not match with controller, rate: 21\n",
      "Class name Blog does not match with dto, rate: 33\n",
      "Class name Blog does not match with handler, rate: 15\n",
      "Class name Blog does not match with interceptor, rate: 20\n",
      "Class name Blog does not match with mapper, rate: 57\n",
      "Class name GoodMapper does not match with config, rate: 29\n",
      "Class name GoodMapper does not match with controller, rate: 33\n",
      "Class name GoodMapper does not match with dto, rate: 43\n",
      "Class name GoodMapper does not match with handler, rate: 38\n",
      "Class name GoodMapper does not match with interceptor, rate: 30\n",
      "Class name ShopMapper does not match with config, rate: 36\n",
      "Class name ShopMapper does not match with controller, rate: 50\n",
      "Class name ShopMapper does not match with dto, rate: 44\n",
      "Class name ShopMapper does not match with handler, rate: 31\n",
      "Class name ShopMapper does not match with interceptor, rate: 30\n",
      "Class name BlogMapper does not match with config, rate: 33\n",
      "Class name BlogMapper does not match with controller, rate: 33\n",
      "Class name BlogMapper does not match with dto, rate: 29\n",
      "Class name BlogMapper does not match with handler, rate: 38\n",
      "Class name BlogMapper does not match with interceptor, rate: 37\n",
      "Class name RegisterService does not match with config, rate: 48\n",
      "Class name RegisterService does not match with controller, rate: 61\n",
      "Class name RegisterService does not match with dto, rate: 67\n",
      "Class name RegisterService does not match with handler, rate: 22\n",
      "Class name RegisterService does not match with interceptor, rate: 41\n",
      "Class name RegisterService does not match with mapper, rate: 44\n",
      "Class name RegisterService does not match with model, rate: 36\n",
      "Class name AlipayConfigMapper does not match with config, rate: 55\n",
      "Class name AlipayConfigMapper does not match with controller, rate: 65\n",
      "Class name AlipayConfigMapper does not match with dto, rate: 41\n",
      "Class name AlipayConfigMapper does not match with handler, rate: 35\n",
      "Class name AlipayConfigMapper does not match with interceptor, rate: 31\n",
      "Class name GlobalExceptionHandler does not match with config, rate: 33\n",
      "Class name GlobalExceptionHandler does not match with controller, rate: 39\n",
      "Class name GlobalExceptionHandler does not match with dto, rate: 35\n",
      "Class name TemplatedErrandInterceptor does not match with config, rate: 40\n",
      "Class name TemplatedErrandInterceptor does not match with controller, rate: 52\n",
      "Class name TemplatedErrandInterceptor does not match with dto, rate: 45\n",
      "Class name TemplatedErrandInterceptor does not match with handler, rate: 38\n",
      "Class name ReplyMapper does not match with config, rate: 40\n",
      "Class name ReplyMapper does not match with controller, rate: 34\n",
      "Class name ReplyMapper does not match with dto, rate: 60\n",
      "Class name ReplyMapper does not match with handler, rate: 30\n",
      "Class name ReplyMapper does not match with interceptor, rate: 35\n",
      "Class name KeywordType does not match with config, rate: 34\n",
      "Class name KeywordType does not match with controller, rate: 32\n",
      "Class name ExceptionMapper does not match with config, rate: 36\n",
      "Class name ExceptionMapper does not match with controller, rate: 38\n",
      "Class name ExceptionMapper does not match with dto, rate: 38\n",
      "Class name ExceptionMapper does not match with handler, rate: 65\n",
      "Class name ExceptionMapper does not match with interceptor, rate: 41\n",
      "Class name LoginRequest does not match with config, rate: 27\n",
      "Class name LoginRequest does not match with controller, rate: 44\n",
      "Class name ShopInfo does not match with config, rate: 35\n",
      "Class name ShopInfo does not match with controller, rate: 55\n",
      "Class name Shop does not match with config, rate: 27\n",
      "Class name Shop does not match with controller, rate: 44\n",
      "Class name Shop does not match with dto, rate: 67\n",
      "Class name Shop does not match with handler, rate: 15\n",
      "Class name Shop does not match with interceptor, rate: 21\n",
      "Class name Shop does not match with mapper, rate: 57\n",
      "Class name UserService does not match with config, rate: 41\n",
      "Class name UserService does not match with controller, rate: 48\n",
      "Class name UserService does not match with dto, rate: 44\n",
      "Class name UserService does not match with handler, rate: 18\n",
      "Class name UserService does not match with interceptor, rate: 38\n",
      "Class name UserService does not match with mapper, rate: 57\n",
      "Class name UserService does not match with model, rate: 53\n",
      "Class name ErrandInterceptorTemplated does not match with config, rate: 45\n",
      "Class name ErrandInterceptorTemplated does not match with controller, rate: 57\n",
      "Class name ErrandInterceptorTemplated does not match with dto, rate: 51\n",
      "Class name ErrandInterceptorTemplated does not match with handler, rate: 33\n",
      "Class name ErrandInterceptorTemplated does not match with interceptor, rate: 65\n",
      "Class name ErrandInterceptorTemplated does not match with mapper, rate: 47\n",
      "Class name ErrandInterceptorTemplated does not match with model, rate: 38\n",
      "Class name ErrandInterceptorTemplated does not match with service, rate: 60\n",
      "Class name ErrandInterceptorTemplated does not match with util, rate: 32\n",
      "Class ErrandInterceptorTemplated not found in any package.\n",
      "Class name User does not match with config, rate: 18\n",
      "Class name User does not match with controller, rate: 44\n",
      "Class name User does not match with dto, rate: 44\n",
      "Class name User does not match with handler, rate: 15\n",
      "Class name User does not match with interceptor, rate: 30\n",
      "Class name User does not match with mapper, rate: 57\n",
      "Class name Errand does not match with config, rate: 17\n",
      "Class name Errand does not match with controller, rate: 55\n",
      "Class name Errand does not match with dto, rate: 52\n",
      "Class name Errand does not match with handler, rate: 29\n",
      "Class name Errand does not match with interceptor, rate: 38\n",
      "Class name Errand does not match with mapper, rate: 67\n",
      "Class name Good does not match with config, rate: 15\n",
      "Class name Good does not match with controller, rate: 22\n",
      "Class name Good does not match with dto, rate: 35\n",
      "Class name Good does not match with handler, rate: 31\n",
      "Class name Good does not match with interceptor, rate: 14\n",
      "Class name Good does not match with mapper, rate: 57\n",
      "Class name ComplaintBlock does not match with config, rate: 36\n",
      "Class name ComplaintBlock does not match with controller, rate: 61\n",
      "Class name ErrandOrderStatus does not match with config, rate: 34\n",
      "Class name ErrandOrderStatus does not match with controller, rate: 55\n",
      "Class name ErrandMapper does not match with config, rate: 33\n",
      "Class name ErrandMapper does not match with controller, rate: 57\n",
      "Class name ErrandMapper does not match with dto, rate: 55\n",
      "Class name ErrandMapper does not match with handler, rate: 35\n",
      "Class name ErrandMapper does not match with interceptor, rate: 42\n",
      "Class name ErrandOrderPreview does not match with config, rate: 39\n",
      "Class name ErrandOrderPreview does not match with controller, rate: 53\n",
      "Class name AlipayController does not match with config, rate: 53\n",
      "Class name BlogToForumPostPreview does not match with config, rate: 35\n",
      "Class name BlogToForumPostPreview does not match with controller, rate: 49\n",
      "Class name TemplatedBanInterceptor does not match with config, rate: 43\n",
      "Class name TemplatedBanInterceptor does not match with controller, rate: 48\n",
      "Class name TemplatedBanInterceptor does not match with dto, rate: 46\n",
      "Class name TemplatedBanInterceptor does not match with handler, rate: 36\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "id": "e6848012",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:35.514509Z",
     "start_time": "2025-05-25T03:01:35.492759Z"
    }
   },
   "source": [
    "refined_md_dir = pathlib.Path(\"refined_md_2\")\n",
    "if not refined_md_dir.exists():\n",
    "    refined_md_dir.mkdir()\n",
    "else:\n",
    "    shutil.rmtree(refined_md_dir)\n",
    "    refined_md_dir.mkdir()"
   ],
   "outputs": [],
   "execution_count": 7
  },
  {
   "cell_type": "code",
   "id": "1765a89f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:35.545284Z",
     "start_time": "2025-05-25T03:01:35.524497Z"
    }
   },
   "source": [
    "plant_uml_dir = pathlib.Path(\"plantuml\")\n",
    "if not plant_uml_dir.exists():\n",
    "    plant_uml_dir.mkdir()\n",
    "else:\n",
    "    shutil.rmtree(plant_uml_dir)\n",
    "    plant_uml_dir.mkdir()"
   ],
   "outputs": [],
   "execution_count": 8
  },
  {
   "cell_type": "code",
   "id": "773ac683",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:35.560037Z",
     "start_time": "2025-05-25T03:01:35.555370Z"
    }
   },
   "source": [
    "def refine_md(class_name,index)->tuple[str,str]:\n",
    "    md_file_path = pathlib.Path(\"md\") /f\"{class_name}.md\"\n",
    "    with open(md_file_path, \"r\", encoding=\"utf-8\") as f:\n",
    "        content = f.read()\n",
    "    main_content_index = len(content.split(\"### 3.1\")[0])\n",
    "    refined_content = content[main_content_index:]\n",
    "    refined_content=refined_content.replace(\"class 3\", class_name)\n",
    "    refined_content=refined_content.replace(\"class3\", class_name)\n",
    "    refined_content=refined_content.replace(\"class1\", class_name)\n",
    "    refined_content=refined_content.replace(\"class 1\", class_name)\n",
    "    refined_content=refined_content.replace(\"# 3\", f\"# {index}\")\n",
    "    plantuml_content = \"\".join(refined_content.split(\"```plantuml\")[1:]).split(\"```\")[0]\n",
    "\n",
    "    \n",
    "    with open(refined_md_dir / f\"{index}--{class_name}.md\", \"w\", encoding=\"utf-8\") as f:\n",
    "        f.write(refined_content)\n",
    "\n",
    "    with open(plant_uml_dir / f\"{index}--{class_name}.puml\", \"w\", encoding=\"utf-8\") as f:\n",
    "        f.write(plantuml_content)\n",
    "    refined_content = refined_content.replace(plantuml_content,\"\\n\\n\\n\\n\\n\")\n",
    "    refined_content = f\"# {index} {class_name}\"+'\\n\\n'+refined_content\n",
    "    return refined_content+'\\n\\n',refined_content.replace(plantuml_content,\"\\n\\n\\n\\n\\n\")"
   ],
   "outputs": [],
   "execution_count": 9
  },
  {
   "cell_type": "code",
   "id": "41d8c8f3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-25T03:01:38.217845Z",
     "start_time": "2025-05-25T03:01:35.574270Z"
    }
   },
   "source": [
    "index = 3\n",
    "outbuf = \"\"\n",
    "prioritized_packages = []\n",
    "\n",
    "\n",
    "prioritized_packages.append(\"controller\")\n",
    "prioritized_packages.append(\"service\")\n",
    "\n",
    "\n",
    "briefed_outbuf = \"\"\n",
    "integrated_dir = pathlib.Path(\"integrated_v2\")\n",
    "if not integrated_dir.exists():\n",
    "    integrated_dir.mkdir()\n",
    "# else:\n",
    "#     shutil.rmtree(integrated_dir)\n",
    "#     integrated_dir.mkdir()\n",
    "for package in prioritized_packages:\n",
    "    if not package in packages.keys():\n",
    "        raise FileNotFoundError(f\"Package {package} not found in any package.\")\n",
    "    print('\\n', package)\n",
    "    outbuf += f\"# {package}\\n\"\n",
    "    for class_name in packages[package]:\n",
    "        print(class_name, ' ', index, end=\" \")\n",
    "        index += 1\n",
    "        refined, raw = refine_md(class_name, index)\n",
    "        outbuf += refined\n",
    "        briefed_outbuf += raw\n",
    "\n",
    "# briefed_outbuf = outbuf\n",
    "\n",
    "for package in packages.keys():\n",
    "    if package in prioritized_packages:\n",
    "        continue\n",
    "    print('\\n', package)\n",
    "    outbuf += f\"# {package}\\n\"\n",
    "    for class_name in packages[package]:\n",
    "        print(class_name, ' ', index, end=\" \")\n",
    "        index += 1\n",
    "        refined, raw = refine_md(class_name, index)\n",
    "        outbuf += refined\n",
    "with open(integrated_dir / \"index.md\", \"w\", encoding=\"utf-8\") as f:\n",
    "    f.write(outbuf)\n",
    "with open(integrated_dir / \"briefed_index.md\", \"w\", encoding=\"utf-8\") as f:\n",
    "    f.write(briefed_outbuf)\n",
    "# Convert the integrated markdown file to docx\n",
    "pypandoc.convert_file(\n",
    "    integrated_dir / \"index.md\",\n",
    "    'docx',\n",
    "    outputfile=integrated_dir / \"index.docx\",\n",
    "\n",
    ")\n",
    "pypandoc.convert_file(\n",
    "    integrated_dir / \"briefed_index.md\",\n",
    "    'docx',\n",
    "    outputfile=integrated_dir / \"briefed_index.docx\",\n",
    "\n",
    ")"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " controller\n",
      "RegisterController   3 LoginController   4 AlipayController   5 ErrorController   6 ErrandController   7 ShopController   8 SessionKeys   9 ComplaintController   10 UserController   11 StockController   12 ForumController   13 \n",
      " service\n",
      "UploadFileSystemService   14 StockService   15 BaseAuthService   16 ExceptionService   17 MailService   18 CampusAidException   19 UserService   20 ErrandService   21 ComplaintService   22 RegisterService   23 ChargeService   24 ShopService   25 LocalUploadFileSystemService   26 LoginService   27 \n",
      " interceptor\n",
      "TemplatedErrandInterceptor   28 BanApiInterceptor   29 TemplatedBanInterceptor   30 BanInterceptor   31 TemplatedForumInterceptor   32 BasicInterceptor   33 AuthInterceptor   34 ApiInterceptor   35 ViewInterceptor   36 \n",
      " mapper\n",
      "ExceptionMapper   37 ErrandViewsMapper   38 ChargeMapper   39 BanMapper   40 GoodMapper   41 UserMapper   42 ComplaintDTOMapper   43 ComplaintMapper   44 ReplyMapperStruct   45 ReplyMapper   46 AlipayConfigMapper   47 ErrandMapper   48 ShopMapper   49 BlogMapper   50 LikeBlogMapper   51 OrderMapper   52 TransactionMapper   53 \n",
      " model\n",
      "GoodTransaction   54 Charge   55 Complaint   56 Good   57 Shop   58 User   59 LikeBlog   60 log   61 ShopOrder   62 Errand   63 BanBlock   64 Ban   65 Blog   66 ReplyTreeNode   67 Reply   68 \n",
      " config\n",
      "AdminConfig   69 WebConfig   70 SecurityProperties   71 AlipayTemplate   72 \n",
      " dto\n",
      "Order   73 BlogToForumPostPreview   74 OrderDTO   75 ErrandOrderRequest   76 ProductTransaction   77 ForumPostPreview   78 ReportRequest   79 RegisterRequest   80 Visibility   81 VerifyRequest   82 ForumPostService   83 ComplaintBlock   84 ErrandOrderStatus   85 PostSortOrder   86 ShopInfo   87 ComplaintRequest   88 KeywordType   89 ErrandOrderPreview   90 LoginRequest   91 ApiResponse   92 ReplyView   93 ProductToGoodTransaction   94 \n",
      " util\n",
      "ReplyTreeConverter   95 \n",
      " handler\n",
      "GlobalExceptionHandler   96 "
     ]
    },
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 10
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
